<#--当前包-->
package ${package.Controller};

<#--开启VO 未开MapStruct 使用BeanUtils-->
<#if enableVo?? && enableVo && !enableMapStruct>
import org.springframework.beans.BeanUtils;
</#if>
<#--导入@RequestMapping注解-->
import java.util.List;
import ${package.Entity}.${entity};
import org.springframework.web.bind.annotation.*;
import ${resultClass};
import ${package.Service}.${table.serviceName};
<#--开启swagger 则导入@Tag、@Operation注解-->
<#if swagger>
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.api.annotations.ParameterObject;
</#if>
<#if enableMapStruct>
import ${mapStructPackage}.${pojoMapStructName};
</#if>
<#if enableVo>
import ${pojoPackageName}.vo.${pojoVOName};
</#if>
<#if enableForm>
import ${pojoPackageName}.saveform.${pojoSaveFormName};
import ${pojoPackageName}.updateform.${pojoUpdateFormName};
</#if>
<#if enableQuery>
import ${pojoPackage}.${pojoQueryName};
</#if>
<#--开启RestControlle 则导入@RestControlle注解，未开启导入@Controlle注解-->
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#--设置了父类，则导入父类-->
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>
<#--导入@RequiredArgsConstructor-->
<#if lombok>
import lombok.RequiredArgsConstructor;
</#if>
<#--类注释部分-->
/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#--开启RestControlle 则添加@RestControlle注解，未开启添加@Controlle注解-->
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
<#--添加@RequestMapping注解-->
<#--请求路径为： 全局配置模块名/实体类名称（可以设置连字符或者驼峰格式）-->
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#--导入@RequiredArgsConstructor-->
<#if lombok>
@RequiredArgsConstructor
</#if>
<#--开启swagger 则添加@Tag、@Operation注解-->
<#if swagger>
@Tag(name = "${table.controllerName}", description = "${table.comment!}管理")
</#if>
<#--设置kotlin模式-->
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#--设置controlle类名、父类-->
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>
<#--设置基础CRUD-->
<#--注入服务类，使用了Lombok 通过构造函数注入，没有则使用@Resource-->
<#if lombok>

    private final ${table.serviceName} ${table.serviceName?uncap_first};
<#else>

    @Resource
    ${table.serviceName} ${table.serviceName?uncap_first};
</#if>
<#--注入MapStruct接口，使用了Lombok 通过构造函数注入，没有则使用@Resource-->
<#if enableMapStruct>
 <#if lombok>

    private final ${pojoMapStructName} ${pojoMapStructName?uncap_first};
 <#else>

    @Resource
    ${pojoMapStructName} ${pojoMapStructName?uncap_first};
 </#if>
</#if>
<#--新增-->
<#if swagger>

    @Operation(summary = "单个新增")
</#if>
    @PostMapping("/save")
    public ${resultName}<?> save(@RequestBody <#if swagger>@ParameterObject </#if><#if enableForm>${pojoSaveFormName}<#else>${entity}</#if> <#if enableForm>${pojoSaveFormName?uncap_first}<#else>${entity?uncap_first}</#if>){
<#if enableForm && enableMapStruct>
    <#--开启了表单、对象映射-->
        ${table.serviceName?uncap_first}.save(${pojoMapStructName?uncap_first}.${pojoSaveFormName?uncap_first}2Entity(${pojoSaveFormName?uncap_first}));
<#elseif enableForm>
        ${entity} ${entity?uncap_first}=new ${entity};
        BeanUtils.copyProperties(${pojoSaveFormName}),${entity?uncap_first});
        ${table.serviceName?uncap_first}.save(${entity?uncap_first});
<#else>
        ${table.serviceName?uncap_first}.save(${entity});
</#if>
        return  ${resultName}.success();
 }
<#if swagger>

    @Operation(summary = "批量新增")
</#if>
    @PostMapping("/saveBatch")
    public ${resultName}<?> saveBatch(@RequestBody <#if swagger>@ParameterObject </#if><#if enableForm>List<${pojoSaveFormName}><#else>List<${entity}></#if> <#if enableForm>${pojoSaveFormName?uncap_first}List<#else>${entity?uncap_first}List</#if>){
<#if enableForm && enableMapStruct>
    <#--开启了表单、对象映射-->
        ${table.serviceName?uncap_first}.saveBatch(${pojoMapStructName?uncap_first}.${pojoSaveFormName?uncap_first}2Entity(${pojoSaveFormName?uncap_first}List));
<#elseif enableForm>
        List<${entity}> ${entity?uncap_first}List=new ArrayList<>();
        BeanUtils.copyProperties(List<${pojoSaveFormName}>,${entity?uncap_first}List);
        ${table.serviceName?uncap_first}.saveBatch(${entity?uncap_first}List);
<#else>
        ${table.serviceName?uncap_first}.saveBatch(${entity?uncap_first}List);
</#if>
        return  ${resultName}.success();
 }
<#--删除-->
<#if swagger>

    @Operation(summary = "根据ID删除")
</#if>
    @DeleteMapping("/remove/{id}")
    public ${resultName}<?> removeById(@PathVariable("id") Long id){
        ${table.serviceName?uncap_first}.removeById(id);
        return  ${resultName}.success();
 }
<#if swagger>

    @Operation(summary = "根据ID集合批量删除")
</#if>
    @DeleteMapping("/remove/{ids}")
    public ${resultName}<?> removeByIds(@PathVariable("ids") List<Long> ids){
        ${table.serviceName?uncap_first}.removeByIds(ids);
        return  ${resultName}.success();
 }
<#--修改-->
<#if swagger>

    @Operation(summary = "修改")
</#if>
    @PutMapping("/update")
    public ${resultName}<?> update(@RequestBody <#if swagger>@ParameterObject </#if><#if enableForm>${pojoUpdateFormName}<#else>${entity}</#if> <#if enableForm>${pojoUpdateFormName?uncap_first}<#else>${entity?uncap_first}</#if>){
<#if enableForm && enableMapStruct>
    <#--开启了表单、对象映射-->
        ${table.serviceName?uncap_first}.updateById(${pojoMapStructName?uncap_first}.${pojoUpdateFormName?uncap_first}2Entity(${pojoUpdateFormName?uncap_first}));
<#elseif enableForm>
        ${entity} ${entity?uncap_first}=new ${entity};
        BeanUtils.copyProperties(${pojoUpdateFormName}),${entity?uncap_first});
        ${table.serviceName?uncap_first}.updateById(${entity?uncap_first});
<#else>
        ${table.serviceName?uncap_first}.updateById(${entity});
</#if>
        return  ${resultName}.success();
 }
</#if>
<#--查询-->
<#if swagger>

    @Operation(summary = "根据ID查询")
</#if>
    @GetMapping("/get/{id}")
<#--没有VO 返回实体类-->
    public ${resultName}<<#if enableVo>${pojoVOName}<#else>${entity}</#if>> getById(@PathVariable("id") Long id){
<#--开启了VO 开启了MapStruct 实体类=》VO-->
<#if enableVo && enableMapStruct>
        return ${resultName}.success(${pojoMapStructName?uncap_first}.${entity?uncap_first}2VO(${table.serviceName?uncap_first}.getById(id)));
<#elseif enableVo>
        ${pojoVOName} ${pojoVOName?uncap_first}=new ${pojoVOName};
        BeanUtils.copyProperties(${table.serviceName?uncap_first}.getById(id),${pojoVOName?uncap_first});
        return ${resultName}.success(${pojoVOName?uncap_first});
<#else>
        return ${resultName}.success(${table.serviceName?uncap_first}.getById(id));
</#if>
 }
<#--&lt;#&ndash;条件分页查询，需要生成Query POJO、指定其分页父类或参数，然后使用MapStruct镜像对象转换&ndash;&gt;
<#if swagger>

 @Operation(summary = "条件查询（分页）")
</#if>
 @GetMapping("/page")
 public Page${resultName}<List<<#if enableVo>${pojoVOName}<#else>${entity}</#if>>> page(@ParameterObject  <#if enableQuery>${pojoQueryName}<#else>${entity}</#if> <#if enableQuery>${pojoQueryName?uncap_first}<#else>${entity?uncap_first}}</#if>) {
    Page<${entity}> page=${table.serviceName?uncap_first}.selectPage(<#if enableQuery>${pojoQueryName?uncap_first}<#else>${entity?uncap_first}</#if>);
<#if enableVo && enableMapStruct>
    List<${pojoVOName}> list=${entity?uncap_first}2VO(page.getRecords());
    return Page${resultName}.success(list, page.getTotal());
<#elseif enableVo>
    List<${pojoVOName}> list=new ArrayList<>();
    BeanUtils.copyProperties(List<${pojoSaveFormName}>,${entity?uncap_first}List);
    return Page${resultName}.success(list, page.getTotal());
<#else>
    return Page${resultName}.success(page.getRecodes(), page.getTotal());
</#if>
}-->

<#if swagger>

    @Operation(summary = "条件查询（不分页）")
</#if>
    @GetMapping("/list")
    public ${resultName}<List<<#if enableVo>${pojoVOName}<#else>${entity}</#if>>> list(@ParameterObject  <#if enableQuery>${pojoQueryName}<#else>${entity}</#if> <#if enableQuery>${pojoQueryName?uncap_first}<#else>${entity?uncap_first}}</#if>){
        List<${entity}> list=${table.serviceName?uncap_first}.selectList(<#if enableQuery>${pojoQueryName?uncap_first}<#else>${entity?uncap_first}</#if>);
<#if enableVo && enableMapStruct>
        List<${pojoVOName}> result=${pojoMapStructName?uncap_first}.${entity?uncap_first}2VO(list);
        return ${resultName}.success(result);
<#elseif enableVo>
        List<${pojoVOName}> result=new ArrayList<>();
        BeanUtils.copyProperties(List<${pojoSaveFormName}>,${entity?uncap_first}List);
        return ${resultName}.success(result);
<#else>
        return ${resultName}.success(list);
</#if>
 }
}